package per.ethan.javase.thread;

import java.util.concurrent.*;

/**
 * @author Ethan
 * @date 2020/04/27 11:04
 */
public class CallbaleTest implements Callable {

    private String url;

    public CallbaleTest(String url) {
        this.url = url;
    }

    @Override
    public Boolean call() throws Exception {
        WebDownload.download(url);
        return true;
    }

    public static void main(String[] args) {
        CallbaleTest t1 = new CallbaleTest("https://ethanloving.top/upload/2020/3/QQ%E5%9B%BE%E7%89%8720200213162707-ab02fd31ae63457ab074e218c713542e.jpg");
        CallbaleTest t2 = new CallbaleTest("https://ethanloving.top/upload/2020/04/image-154836b2baf04ebd8a7d293f0e24495c.png");

        ExecutorService executorService = Executors.newFixedThreadPool(2);

        Future<?> submit = executorService.submit(t1);
        Future<?> submit1 = executorService.submit(t2);

        try {
            submit.get();
            submit1.get();

            executorService.shutdownNow();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }


}
